<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #dv {
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            overflow: auto;
            white-space: pre-wrap;
            max-height: 100vh;
        }

        button {
            position: fixed;
            bottom: 100px;
            right: 20px;
        }
    </style>
</head>

<body>
    <div style="height:4000px"></div>
    <div id="dv"></div>
    <button>back</button>
    <script>
        var str = ''
        // 注意字符串的拼接技术哈！
        document.addEventListener('scroll', () => {

            str += '\n此时窗口的高度为：' + document.scrollingElement.scrollTop
            // 
            dv.innerHTML = str
            // console.log(str)
            var btn = document.getElementsByTagName('button')[0]
            // console.log(btn)
            btn.addEventListener('click', function () {
                console.log(document.scrollingElement.scrollTop = '30')
                // document.scrollingElement.scrollTop = '30px'
            })

        })

    </script>
</body>

</html>